//===================================================================================
// $$
//
// Coder: Code Milker v1.0
// 0 - EntityName
// 1 - lower
//===================================================================================


namespace App.Data.SqlServer.Repositories {
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using App.Model;

    public class CertificationRepository : BaseRepository, ICertificationRepository {
        public CertificationRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork) {
        }
        public void Create(Certification certification) {
            this.GetDbSet<Certification>().Add(certification);
            this.UnitOfWork.SaveChanges();
        }

        public Certification GetCertification(Guid certificationId) {
            return this.GetDbSet<Certification>()
                .Where(c => c.Id == certificationId)
                .Single();
        }

        public void Update(Certification updatedCertification) {
            this.GetDbSet<Certification>().Attach(updatedCertification);
            this.SetEntityState(updatedCertification, updatedCertification.Id == Guid.Empty
                ? EntityState.Added
                : EntityState.Modified);
            this.UnitOfWork.SaveChanges();
        }

        public void Delete(Guid certificationId) {
            Certification CertificationToDelete = this.GetCertification(certificationId);
            this.GetDbSet<Certification>().Remove(CertificationToDelete);
            this.UnitOfWork.SaveChanges();
        }

        public IQueryable<Certification> Find()
        {
            return this.GetDbSet<Certification>();
        }

        public IQueryable<Certification> GetAll()
        {
            return this.GetDbSet<Certification>();
        }
    }
}
